{extend name="public:base" /}
{block name="body"}
<!-- 主体 -->
<div class="row">
    <!-- 左侧8列 -->
    <div class="col-md-8">
        <!-- 页头 -->
        <div class="page-header">
            <h2>{$art.cate_id}</h2>
        </div>
        <div>
            <h4>{$art.title}</h4>
            <p>作者：{$art.user_id}&nbsp;&nbsp;发布时间：{$art.create_time}&nbsp;&nbsp;阅读量：{$art.pv}</p>
            <div>{:htmlspecialchars_decode($art.content)}</div>
            <hr/>
            <button type="button" class="btn btn-default" id="fav" article_id="{$art.id}">收藏</button>
        </div>
    </div>
    {/block}
    {block name="js"}
    <script>
        $(function(){
            $('#fav').on('click', function(){
                var sender = $(this);
                var artId = sender.attr('article_id')
                if (artId){
                    $.ajax({
                        url : "{:url('fav')}",
                        data : {artId},
                        dataType : 'json',
                        success(res){
                            switch (res.status) {
                                case 2:
                                    sender.attr('class', 'btn btn-success')
                                    sender.text(res.msg)
                                    break
                                case 1:
                                    sender.attr('class', 'btn btn-default')
                                    sender.text(res.msg)
                                    break;
                                default:
                                    alert(res.msg)
                                    break
                            }
                        }
                    })
                }
            })
        })
    </script>
    {/block}